package com.yl.ydk.ui.activity

import android.content.Intent
import android.view.View
import com.yl.ydk.R
import com.yl.ydk.base.BaseActivity
import com.yl.ydk.bean.HealthtestQuestionBean
import com.yl.ydk.bean.TestFinishBean
import com.google.gson.Gson
import kotlinx.android.synthetic.main.activity_test_finish.*
import kotlinx.android.synthetic.main.roob_bar.*

class TestFinishActivity : BaseActivity(), View.OnClickListener {


    private var testFinishBean: TestFinishBean? = null
    private var healthtestQuestionBean: HealthtestQuestionBean? = null
    override fun getLayoutId(): Int = R.layout.activity_test_finish

    override fun attachView() {

    }

    override fun detachView() {

    }

    override fun initView() {

        rlBack.setOnClickListener(this)
        btnAgain.setOnClickListener(this)
        testFinishBean = Gson().fromJson<TestFinishBean>(
            intent.getStringExtra("data"),
            TestFinishBean::class.java
        )
        testFinishBean?.data?.let {
            tvDes.text = it.des
            tvResult.text = it.result
        }
        healthtestQuestionBean = Gson().fromJson<HealthtestQuestionBean>(
            intent.getStringExtra("healthtestQuestionBean"),
            HealthtestQuestionBean::class.java
        )
        healthtestQuestionBean?.data?.subject?.let {
            tvName.text = it.title + "评估"
        }

    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.rlBack -> {
                finish()
            }
            R.id.btnAgain -> {
                val intent = Intent(this,HealthtestQuestionActivity::class.java)
                intent.putExtra("testId",healthtestQuestionBean?.data?.subject?.question_id)
                startActivityIn(intent,this)
                finish()
            }
        }
    }

}